package io.kimmking.dubbo.demo.services;

import io.kimmking.dubbo.common.entity.Order;
import io.kimmking.dubbo.common.entity.OrderService;
import io.kimmking.dubbo.common.entity.User;
import io.kimmking.dubbo.common.entity.UserService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

@Service
public class User_Order_ServiceImpl implements testHystrix{
    //dubbo下的服务熔断降级使用mock来实现,当调用服务提供者超时时，则自动切换到mock的定义的方法逻辑中
    //check=true/false表示服务调用者启动时是否会首先发起RPC远程调用测试服务调用是否成功
    @DubboReference(version = "1.0.0", id = "UserService", check = false, timeout = 3000, interfaceClass = UserService.class, mock = "true")
    private UserService userService;

    @DubboReference(version = "1.0.0",id = "OrderService",check = false,timeout = 3000,interfaceClass = OrderService.class,mock = "true")
    private OrderService orderService;

    @Override
    public String getUserOrderInfo() {
        User user = userService.findById(1);
        Order order = orderService.findOrderById(1992129);

        return "find user id=1 from server: " + user.getName() + "\n"
                + String.format("find order name=%s, amount=%f",order.getProCode(),order.getOrderCost());
//        return "find user id=1 from server: " + user.getName();
//        return String.format("find order name=%s, amount=%f",order.getName(),order.getAmount());
    }
}
